/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package types;

import server.entities.Account;
import server.entities.Transaction;
import server.entities.TransactionType;
import server.entities.User;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;

/**
 *
 * @author efim
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="response")
public class ResponseXML<T> {

    public ResponseXML() {
        this.data = new Data<>();
    }
    

    public ResponseXML(Data<T> data) {
        this.data = data;
    }

    public ResponseXML(T item) {
        this.data = new Data<>();
        this.data.items.add(item);
    }

    public ResponseXML(List<T> items) {
        this.data = new Data<>(items);        
    }
    
    
    @XmlElement(name="items")
    private Data<T> data;

    public Data<T> getData() {
        return data;
    }
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlRootElement
    @XmlSeeAlso({User.class,Account.class,Transaction.class,TransactionType.class, AuthXML.class})    
    public static class Data<T>
    {        

        public Data() {
            this.items = new LinkedList<>();
        }

        public Data(List<T> data) {
            this.items = new LinkedList<>(data);
        }

        @XmlElement(name="item")
        private List<T> items;

        public List<T> getItems() {
            return items;
        }
    }

    
}
